package cn.wolfcode.p2p.base.domain;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 视频认证
 */
@Setter@Getter
public class VideoAuth extends BaseAuditDomain{
    private OrderTime orderTime; //时间段
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date orderDate; //预约日期

    /**
     * 返回json数据,后台审核用
     * @return
     */
    public String getJson(){
        Map<Object, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("username", getApplier().getUsername());
        map.put("orderTime", getCompleteOrderTime());
        try {
            return new ObjectMapper().writeValueAsString(map);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 完成预约时间
     * @return
     */
    public String getCompleteOrderTime(){
        return DateFormat.getDateInstance().format(getOrderDate()) + " " + orderTime.getBegin() + "-" + orderTime.getEnd();
    }


}